package com.example.distillapplication.data.database;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.example.distillapplication.data.dao.OperationLogDao;
import com.example.distillapplication.data.dao.UserInfoDao;
import com.example.distillapplication.data.entity.OperationLog;
import com.example.distillapplication.data.entity.UserInfo;

@Database(entities = {UserInfo.class, OperationLog.class}, version = 1,exportSchema = false)
public abstract class AppDataBase extends RoomDatabase {
    private static AppDataBase INSTANCE;//单例模式

    public static synchronized AppDataBase getDataBase(final Context context){
        if(INSTANCE==null){
            INSTANCE = Room.databaseBuilder(context.getApplicationContext(),AppDataBase.class,"appDataBase")
                    .allowMainThreadQueries() //允许主线程访问
                    .build();
        }
        return INSTANCE;
    }

    public abstract UserInfoDao getUserInfoDao();
    public abstract OperationLogDao getOperationLogDao();
}
